package com.qfjy.controller.example5;


import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("blog")
@Slf4j
public class BlogController {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @GetMapping("send")
    @ResponseBody
    public String send(HttpServletRequest request){

        //内容
        String msg=request.getParameter("msg");
        // Java/Python/H5...
        String flag=request.getParameter("flag");
        /**
         * 我要把Java类别文章内容发给 张三和李四
         * if(flag=="java")
         *    .....
         *   MQ 主题模式
         */
        rabbitTemplate.convertAndSend("blogTopicExchange",flag,msg);

        return "发表博客文章成功--->"+msg+"\t==》"+flag;
    }
}
